package com.hbx.gift.util;

import com.hbx.gift.enums.SystemErrorCode;
import lombok.Data;

@Data
public class AjaxResult {
    private String msg;
    private Integer code=200;
    private Boolean success;
    private Object data;

    public AjaxResult(){
        this.success = true;
    }

    public static AjaxResult success(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.msg = "操作成功";
        ajaxResult.success = true;
        return ajaxResult;
    }
    public static AjaxResult success(Object obj){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.msg = "操作成功";
        ajaxResult.success = true;
        ajaxResult.data = obj;
        return ajaxResult;
    }

    public static AjaxResult error(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.msg = "操作失败";
        ajaxResult.success = false;
        return ajaxResult;
    }
    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.msg = msg;
        ajaxResult.success = false;
        return ajaxResult;
    }

    public static AjaxResult error(String msg,Integer code){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.code = code;
        ajaxResult.msg = msg;
        ajaxResult.success = false;
        return ajaxResult;
    }

    public static AjaxResult error(SystemErrorCode systemErrorCode){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.msg = systemErrorCode.getMsg();
        ajaxResult.code= systemErrorCode.getCode();
        ajaxResult.success = false;
        return ajaxResult;
    }
}
